/****************************************************************************
 * Copyright 2010 Huascar A. Sanchez                                        *
 *                                                                          *
 * Licensed under the Apache License, Version 2.0 (the "License");          *
 * you may not use this file except in compliance with the License.         *
 * You may obtain a copy of the License at                                  *
 *                                                                          *
 *     http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                          *
 * Unless required by applicable law or agreed to in writing, software      *
 * distributed under the License is distributed on an "AS IS" BASIS,        *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
 * See the License for the specific language governing permissions and      *
 * limitations under the License.                                           *
 ****************************************************************************/
package com.gotobject.greatq;

import com.gotobject.junit.ConfigureWith;
import com.gotobject.junit.If;
import com.gotobject.junit.Load;
import com.gotobject.junit.Response;
import com.gotobject.junit.Throughput;
import com.gotobject.junit.runner.Launcher;
import com.gotobject.junit.runners.ConditionalJUnitPerfClassRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.gotobject.greatq.ModuleMaker.makeModule;

/**
 * @author huascar.sanchez@gmail.com (Huascar A. Sanchez)
 */
@RunWith(ConditionalJUnitPerfClassRunner.class)
public class StressedQueryServiceTest {
    PurgedQueryService qs = null;
    public static void main(String[] args) {
        Launcher.of(StressedQueryServiceTest.class);
    }

    @Before
    public void setUp() throws Exception {
        qs = new PurgedQueryService(
                (QueryServiceImpl) GreatQ.createQueryService(
                        makeModule("Select * from teste", "qry1")
                )
        );
    }

    @Load("performanceData")
    @Test
    @If(condition = "isOk")    
    public void loadTesting_Using_1000_Users_4_Iterations(){
        qs.fetchResult("qry1");
    }

    @Throughput("performanceData")
    @Test(timeout = 70000)
    @If(condition = "isOk")
    public void throughput_UsingHundredUsers_TwoIterations() {
        qs.fetchResult("qry1");
    }

    @Response("responseData")
    @Test(timeout = 70000)
    @If(condition = "isOk")
    public void responseTesting_UsingHundredUsers_TwoIterations() {
        qs.fetchResult("qry1");
    }

    @ConfigureWith
    public static Object[][] performanceData(){
        // new Object[] {users, and iterations}
        return new Object[][]{
                new Object[]{100, 2}
        };
    }

    public static boolean isOk(){
        return false;
    }

    @ConfigureWith
    public static Object[][] responseData(){
        // new Object[] {users, and iterations}
        return new Object[][]{
                new Object[]{100, 2}
        };
    }

    public void tearDown() throws Exception {
        qs.purge();
        qs = null;
    }
}
